package com.test.down.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.test.down.beans.BaseBean
import com.test.down.R
import com.test.down.adapter.holders.LiveHolders
import com.test.down.adapter.holders.TsHolders

class MainLiveAdapter(val context:Context):RecyclerView.Adapter<BaseHolders>(){

    private val datas=ArrayList<BaseBean>()

    var type=0;

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseHolders {
        return when(type){
            0->{
                LiveHolders(context, View.inflate(context, R.layout.item_live_layout,null))
            }
            1->{
                TsHolders(context, View.inflate(context, R.layout.item_ts_files,null))
            }
            else->{
                LiveHolders(context, View.inflate(context, R.layout.item_live_layout,null))
            }
        }
    }

    override fun onBindViewHolder(holder: BaseHolders, position: Int) {
        holder.setItemData(datas[position],position)
    }

    override fun getItemCount(): Int {
        return datas.size
    }

    fun upData(beans:List<BaseBean>){
        datas.clear()
        datas.addAll(beans)
        notifyDataSetChanged()
    }

    fun setNewItem(beans: BaseBean){
        datas.add(beans)
        notifyItemRangeInserted(datas.size,1)
    }

}